<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Spring学习-5 | Kylin</title><meta name="keywords" content="spring,aop,面向切面编程,Schema-based,前置通知,后置通知,异常通知,环绕通知,jdk动态代理,cglib动态代理"><meta name="author" content="Kylin"><meta name="copyright" content="Kylin"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="AOP（面向切面编程）英文名称:(Aspect Oriented Programming) 正常程序执行流程都是纵向执行流程 又叫面向切面编程,在原有纵向执行流程中添加横切面  特点： 不需要修改原有程序代码 高扩展性 原有功能相当于释放了部分逻辑.让职责更加明确.">
<meta property="og:type" content="article">
<meta property="og:title" content="Spring学习-5">
<meta property="og:url" content="https://www.codekylin.cn/27466.html">
<meta property="og:site_name" content="Kylin">
<meta property="og:description" content="AOP（面向切面编程）英文名称:(Aspect Oriented Programming) 正常程序执行流程都是纵向执行流程 又叫面向切面编程,在原有纵向执行流程中添加横切面  特点： 不需要修改原有程序代码 高扩展性 原有功能相当于释放了部分逻辑.让职责更加明确.">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://qiniu.codekylin.cn/github/img/img/wallhaven-nm97v9.jpg">
<meta property="article:published_time" content="2019-11-02T14:01:51.000Z">
<meta property="article:modified_time" content="2022-07-12T11:42:49.990Z">
<meta property="article:author" content="Kylin">
<meta property="article:tag" content="spring">
<meta property="article:tag" content="aop">
<meta property="article:tag" content="面向切面编程">
<meta property="article:tag" content="Schema-based">
<meta property="article:tag" content="前置通知">
<meta property="article:tag" content="后置通知">
<meta property="article:tag" content="异常通知">
<meta property="article:tag" content="环绕通知">
<meta property="article:tag" content="jdk动态代理">
<meta property="article:tag" content="cglib动态代理">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://qiniu.codekylin.cn/github/img/img/wallhaven-nm97v9.jpg"><link rel="shortcut icon" href="https://qiniu.codekylin.cn/img/20200807181548.png"><link rel="canonical" href="https://www.codekylin.cn/27466"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//www.google-analytics.com" crossorigin=""/><link rel="preconnect" href="//hm.baidu.com"/><link rel="preconnect" href="//fonts.googleapis.com" crossorigin=""/><meta name="google-site-verification" content="gzeyWstt6NoTZKh7YFYNLNziL8HIZ8YH2Ug7xTDX5-Y"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.css" media="print" onload="this.media='all'"><script>var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?f76c34daefe747deee7c7be3ead2ba80";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script><script async="async" src="https://www.googletagmanager.com/gtag/js?id=UA-159334016-1"></script><script>window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-159334016-1');
</script><link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Titillium+Web" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: {"path":"search.xml","languages":{"hits_empty":"找不到您查询的内容：${query}"}},
  translate: {"defaultEncoding":2,"translateDelay":0,"msgToTraditionalChinese":"繁","msgToSimplifiedChinese":"简"},
  noticeOutdate: {"limitDay":90,"position":"top","messagePrev":"自上次更新以来已经","messageNext":"天，文章的内容可能已过时或存在差异。"},
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '天',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: {"limitCount":50000,"languages":{"author":"作者: Kylin","link":"链接: ","source":"来源: Kylin","info":"著作权归作者所有。商业转载请联系作者获得授权，非商业转载请注明出处。"}},
  lightbox: 'fancybox',
  Snackbar: {"chs_to_cht":"你已切换为繁体","cht_to_chs":"你已切换为简体","day_to_night":"你已切换为深色模式","night_to_day":"你已切换为浅色模式","bgLight":"#FF0000","bgDark":"#2d3035","position":"bottom-left"},
  source: {
    jQuery: 'https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js',
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/js/jquery.justifiedGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/css/justifiedGallery.min.css'
    },
    fancybox: {
      js: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.js',
      css: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: true,
  isanchor: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = { 
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2022-07-12 19:42:49'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          const isDarkMode = window.matchMedia('(prefers-color-scheme: dark)').matches
          const isLightMode = window.matchMedia('(prefers-color-scheme: light)').matches
          const isNotSpecified = window.matchMedia('(prefers-color-scheme: no-preference)').matches
          const hasNoSupport = !isDarkMode && !isLightMode && !isNotSpecified

          if (t === undefined) {
            if (isLightMode) activateLightMode()
            else if (isDarkMode) activateDarkMode()
            else if (isNotSpecified || hasNoSupport) {
              const now = new Date()
              const hour = now.getHours()
              const isNight = hour <= 6 || hour >= 18
              isNight ? activateDarkMode() : activateLightMode()
            }
            window.matchMedia('(prefers-color-scheme: dark)').addListener(function (e) {
              if (saveToLocal.get('theme') === undefined) {
                e.matches ? activateDarkMode() : activateLightMode()
              }
            })
          } else if (t === 'light') activateLightMode()
          else activateDarkMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const fontSizeVal = saveToLocal.get('global-font-size')
    if (fontSizeVal !== undefined) {
      document.documentElement.style.setProperty('--global-font-size', fontSizeVal + 'px')
    }
    })(window)</script><link rel="stylesheet" href="https://qiniu.codekylin.cn/github/img/img/custom.css"><link rel="stylesheet" href="//at.alicdn.com/t/font_1993646_z05rabxf05h.css"><link rel="stylesheet" href="https://qiniu.codekylin.cn/github/img/img/icon.css"><meta name="generator" content="Hexo 5.4.0"><link rel="alternate" href="/atom.xml" title="Kylin" type="application/atom+xml">
</head><body><div id="web_bg"></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="author-avatar"><img class="avatar-img" data-lazy-src="https://qiniu.codekylin.cn/img/20200807181526.jpg" onerror="onerror=null;src='https://qiniu.codekylin.cn/github/img/friend_404.gif'" alt="avatar"/></div><div class="site-data"><div class="data-item is-center"><div class="data-item-link"><a href="/archives/"><div class="headline">文章</div><div class="length-num">362</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/tags/"><div class="headline">标签</div><div class="length-num">427</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/categories/"><div class="headline">分类</div><div class="length-num">101</div></a></div></div></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fa fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fa fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fa fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fa fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fa fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fa fa-heart"></i><span> 关于</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('https://qiniu.codekylin.cn/github/img/img/wallhaven-nm97v9.jpg')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/">Kylin</a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fa fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fa fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fa fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fa fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fa fa-link"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fa fa-heart"></i><span> 关于</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">Spring学习-5</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2019-11-02T14:01:51.000Z" title="发表于 2019-11-02 22:01:51">2019-11-02</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2022-07-12T11:42:49.990Z" title="更新于 2022-07-12 19:42:49">2022-07-12</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/SSM/">SSM</a><i class="fas fa-angle-right post-meta-separator"></i><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/SSM/Spring/">Spring</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-wordcount"><i class="far fa-file-word fa-fw post-meta-icon"></i><span class="post-meta-label">字数总计:</span><span class="word-count">1.7k</span><span class="post-meta-separator">|</span><i class="far fa-clock fa-fw post-meta-icon"></i><span class="post-meta-label">阅读时长:</span><span>5分钟</span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h2 id="AOP（面向切面编程）"><a href="#AOP（面向切面编程）" class="headerlink" title="AOP（面向切面编程）"></a>AOP（面向切面编程）</h2><p><strong>英文名称:(Aspect Oriented Programming)</strong></p>
<p><strong>正常程序执行流程都是纵向执行流程</strong></p>
<p><strong>又叫面向切面编程,在原有纵向执行流程中添加横切面</strong></p>
<ul>
<li><strong>特点：</strong><ul>
<li><strong>不需要修改原有程序代码</strong></li>
<li><strong>高扩展性</strong></li>
<li><strong>原有功能相当于释放了部分逻辑.让职责更加明确.</strong><span id="more"></span></li>
</ul>
</li>
</ul>
<p><strong>面向切面编程是什么?</strong></p>
<ul>
<li><p><strong>在程序原有纵向执行流程中,针对某一个或某一些方法添加通知,形成横切面过程就叫做面向切面编程.</strong></p>
</li>
<li><p><strong>常用概念</strong></p>
<ul>
<li><strong>原有功能: 切点,pointcut</strong></li>
<li><strong>前置通知: 在切点之前执行的功能.beforeadvice</strong></li>
<li><strong>后置通知: 在切点之后执行的功能,afteradvice</strong></li>
<li><strong>如果切点执行过程中出现异常,会触发异常通知.throwsadvice</strong></li>
<li><strong>所有功能总称叫做切面.</strong></li>
<li><strong>织入: 把切面嵌入到原有功能的过程叫做织入</strong></li>
<li><strong>spring 提供了 2 种 AOP 实现方式</strong><ul>
<li><strong>Schema-based</strong><ul>
<li><strong>每个通知都需要实现接口或类</strong></li>
<li><strong>配置 spring 配置文件时在<code>&lt;aop:config&gt;</code>配置</strong></li>
</ul>
</li>
<li><strong>AspectJ</strong><ul>
<li><strong>每个通知不需要实现接口或类</strong></li>
<li><strong>配置 spring 配置文件是在<code>&lt;aop:config&gt;</code>的子标签<code>&lt;aop:aspect&gt;</code>中配置</strong></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<p>1）目标方法的调用由环绕通知决定，即你可以决定是否调用目标方法，而前置和后置通知  是不能决定的，他们只是在方法的调用前后执行通知而已，即目标方法肯定是要执行的。</p>
<p>2） 环绕通知可以控制返回对象，即你可以返回一个与目标对象完全不同的返回值，虽然这很危险，但是你却可以办到。而后置方法是无法办到的，因为他是在目标方法返回值后调用</p>
<h2 id="Schema-based-实现AOP"><a href="#Schema-based-实现AOP" class="headerlink" title="Schema-based 实现AOP"></a>Schema-based 实现AOP</h2><p>导入jar<br><img src= "https://gitee.com/kylincw/images/raw/master/loading.gif" data-lazy-src="https://qiniu.codekylin.cn/img/20200405111522.png" alt=""></p>
<h3 id="前置通知"><a href="#前置通知" class="headerlink" title="前置通知"></a>前置通知</h3><p><strong>新建前置通知类–实现<mark>MethodBeforeAdvice</mark>接口</strong></p>
<ul>
<li><strong>method: 切点方法对象 Method 对象</strong></li>
<li><strong>objects: 切点方法参数</strong></li>
<li><strong>o:切点在哪个对象中</strong></li>
</ul>
<p>​    <img src= "https://gitee.com/kylincw/images/raw/master/loading.gif" data-lazy-src="https://qiniu.codekylin.cn/img/20200405111524.png" alt=""></p>
<h3 id="后置通知"><a href="#后置通知" class="headerlink" title="后置通知"></a>后置通知</h3><p><strong>1.新建后置通知类–实现<mark>AfterReturningAdvice</mark>接口</strong></p>
<ul>
<li><strong>o:切点方法返回值</strong></li>
<li><strong>method:切点方法对象</strong></li>
<li><strong>objects:切点方法参数</strong></li>
<li><strong>o1:切点方法所在类的对象</strong></li>
</ul>
<p><img src= "https://gitee.com/kylincw/images/raw/master/loading.gif" data-lazy-src="https://qiniu.codekylin.cn/img/20200405111523.png" alt=""></p>
<p><strong>2.配置 spring 配置文件</strong></p>
<ul>
<li><strong>引入 aop 命名空间</strong></li>
<li><strong>配置通知类的&lt;-bean&gt;</strong></li>
<li><strong>配置切面</strong></li>
<li><strong><code>‘*’</code>通配符,匹配任意方法名,任意类名,任意一级包名</strong></li>
<li><strong>如果希望匹配任意方法参数 <code>(..)</code></strong></li>
</ul>
<p><img src= "https://gitee.com/kylincw/images/raw/master/loading.gif" data-lazy-src="https://qiniu.codekylin.cn/img/20200405111525.png" alt=""></p>
<p><strong>3.测试</strong></p>
<p><img src= "https://gitee.com/kylincw/images/raw/master/loading.gif" data-lazy-src="https://qiniu.codekylin.cn/img/20200405111528.png" alt=""></p>
<h3 id="异常通知"><a href="#异常通知" class="headerlink" title="异常通知"></a>异常通知</h3><p><strong>1.异常通知–实现<mark>ThrowsAdvice</mark>接口</strong></p>
<ul>
<li><strong>必须自己写方法,且必须叫<code>afterThrowing</code></strong></li>
<li><strong>有两种参数方式 必须是 1 个或 4 个</strong></li>
<li><strong>异常类型要与切点报的异常类型一致</strong></li>
</ul>
<p><img src= "https://gitee.com/kylincw/images/raw/master/loading.gif" data-lazy-src="https://qiniu.codekylin.cn/img/20200405111526.png" alt=""></p>
<p><img src= "https://gitee.com/kylincw/images/raw/master/loading.gif" data-lazy-src="https://qiniu.codekylin.cn/img/20200405111527.png" alt=""></p>
<p><strong>2.在 ApplicationContext.xml 配置</strong><br><img src= "https://gitee.com/kylincw/images/raw/master/loading.gif" data-lazy-src="https://qiniu.codekylin.cn/img/20200405111529.png" alt=""></p>
<p><strong>3.测试</strong></p>
<p><img src= "https://gitee.com/kylincw/images/raw/master/loading.gif" data-lazy-src="https://qiniu.codekylin.cn/img/20200405111532.png" alt=""></p>
<h3 id="环绕通知"><a href="#环绕通知" class="headerlink" title="环绕通知"></a>环绕通知</h3><p><strong>1.环绕通知–实现<mark>MethodInterceptor</mark>接口</strong></p>
<p>新建一个类实现 MethodInterceptor<br><img src= "https://gitee.com/kylincw/images/raw/master/loading.gif" data-lazy-src="https://qiniu.codekylin.cn/img/20200405111531.png" alt=""></p>
<p><strong>2.配置spring配置文件</strong><br><img src= "https://gitee.com/kylincw/images/raw/master/loading.gif" data-lazy-src="https://qiniu.codekylin.cn/img/20200405111530.png" alt=""></p>
<p><strong>3.测试</strong></p>
<p><img src= "https://gitee.com/kylincw/images/raw/master/loading.gif" data-lazy-src="https://qiniu.codekylin.cn/img/20200405111533.png" alt=""></p>
<h3 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h3><p><strong>新建一个通知，要创建一个类来实现相应通知的接口。</strong></p>
<p><strong>在spring配置文件中，首先要通过bean标签将通知类交给spring实例化。然后通过aop:config标签配置切面，在此标签下通过aop:pointcut配置切点，expression属性配置切点的具体所在位置。通过aop:advisor标签引入相应已经给spring实例类。</strong></p>
<h2 id="AspectJ方式实现AOP"><a href="#AspectJ方式实现AOP" class="headerlink" title="AspectJ方式实现AOP"></a>AspectJ方式实现AOP</h2><h3 id="xml"><a href="#xml" class="headerlink" title="xml"></a>xml</h3><p><strong>1.新建类,不用实现。类中方法名任意</strong><img src= "https://gitee.com/kylincw/images/raw/master/loading.gif" data-lazy-src="https://qiniu.codekylin.cn/img/20200405111534.png" alt=""></p>
<p><strong>2.配置 spring 配置文件</strong></p>
<ul>
<li><p><strong><code>&lt;aop:after/&gt;</code> 后置通知,是否出现异常都执行</strong></p>
</li>
<li><p><strong><code>&lt;aop:after-returing/&gt;</code> 后置通知,只有当切点正确执行时执行</strong></p>
</li>
<li><p><strong><code>&lt;aop:after/&gt;</code> 和 <code>&lt;aop:after-returing/&gt;</code>和<code>&lt;aop:after-throwing/&gt;</code>执行顺序和配置顺序有关</strong></p>
</li>
<li><p><strong>execution() 括号不能扩上 args</strong></p>
</li>
<li><p><strong>中间使用 and 不能使用&amp;&amp; 由 spring 把 and 解析成&amp;&amp;</strong></p>
</li>
<li><p><strong>args(名称) 名称自定义的.顺序和 demo1(参数,参数)对应</strong></p>
</li>
<li><p><strong><code>&lt;aop:before/&gt;</code> arg-names=” 名称 ” 名称来源 于expression=”” 中 args(),名称必须一样</strong></p>
<ul>
<li><strong>args() 有几个参数,arg-names 里面必须有几个参数</strong></li>
</ul>
</li>
<li><p><strong>arg-names=”” 里面名称必须和通知方法参数名对应</strong></p>
<p>  <img src= "https://gitee.com/kylincw/images/raw/master/loading.gif" data-lazy-src="https://qiniu.codekylin.cn/img/20200405111537.png" alt=""></p>
<p>  <img src= "https://gitee.com/kylincw/images/raw/master/loading.gif" data-lazy-src="https://qiniu.codekylin.cn/img/20200405111535.png" alt=""></p>
</li>
</ul>
<h3 id="总结-1"><a href="#总结-1" class="headerlink" title="总结"></a>总结</h3><p><strong>使用AspectJ方式不需要实现通知接口，自定义通知方法。</strong></p>
<p><strong>在spring配置文件中首先通过bean标签将存在通知方法的的类交给spring管理实例化。在通过aop:config标签配置切面，在标签内使用aop:aspect标签声明使用的是AspectJ方式并通过ref引用含有通知方法的类。通过aop:pointcut配置切点expression属性配置切点的具体所在位置。通过aop:before标签声明前置通知，aop:after标签声明后置通知，aop:after-throwing声明异常通知，aop:around声明环绕通知。此类标签通过pointcut-ref引用切点，method引用具体方法，arg-names引用参数。</strong></p>
<h3 id="注解"><a href="#注解" class="headerlink" title="注解"></a>注解</h3><p><strong>spring 不会自动去寻找注解,必须告诉 spring 哪些包下的类中可能有注解，引入<code>xmlns:context</code>和<code>&lt;context:component-scan&gt;</code>标签</strong><br><img src= "https://gitee.com/kylincw/images/raw/master/loading.gif" data-lazy-src="https://qiniu.codekylin.cn/img/20200405111536.png" alt=""></p>
<p>@Component</p>
<ul>
<li><strong>相当于<code>&lt;bean&gt;</code></strong></li>
<li><strong>如果括号里没有参数,默认实例化后id为把类名首字母变小写,相当于&lt;-bean id=””/&gt;</strong></li>
<li><strong>@Component(“自定义名称”)</strong></li>
</ul>
<p>在 Demo 类中添加@Componet，<strong>在方法上添加<code>@Pointcut(“execution(* 包名+类名+方法名”)</code>定义切点</strong><br><img src= "https://gitee.com/kylincw/images/raw/master/loading.gif" data-lazy-src="https://qiniu.codekylin.cn/img/20200405111538.png" alt=""></p>
<p><strong>在通知类中配置</strong></p>
<ul>
<li><strong>@Component 类被 spring 管理</strong></li>
<li><strong>@Aspect 相当于<code>&lt;aop:aspect/&gt;</code>表示通知方法在当前类中</strong></li>
</ul>
<p><img src= "https://gitee.com/kylincw/images/raw/master/loading.gif" data-lazy-src="https://qiniu.codekylin.cn/img/20200405111540.png" alt=""></p>
<p>spring配置文件中修改代理模式默认为jdk模式</p>
<p><img src= "https://gitee.com/kylincw/images/raw/master/loading.gif" data-lazy-src="https://qiniu.codekylin.cn/img/20200405111539.png" alt=""></p>
<h2 id="代理设计模式"><a href="#代理设计模式" class="headerlink" title="代理设计模式"></a>代理设计模式</h2><p><strong>设计模式:前人总结的一套解决特定问题的代码.</strong></p>
<ul>
<li>代理设计模式优点:<ul>
<li><strong>保护真实对象</strong></li>
<li><strong>让真实对象职责更明确.</strong></li>
<li><strong>扩展</strong></li>
</ul>
</li>
<li>代理设计模式<ul>
<li><strong>真实对象.(老总)</strong></li>
<li><strong>代理对象(秘书)</strong></li>
<li><strong>抽象对象(抽象功能),谈小目标</strong></li>
</ul>
</li>
</ul>
<h3 id="静态代理设计模式"><a href="#静态代理设计模式" class="headerlink" title="静态代理设计模式"></a>静态代理设计模式</h3><ul>
<li>由代理对象代理所有真实对象的功能.<ul>
<li>自己编写代理类</li>
<li>每个代理的功能需要单独编写</li>
</ul>
</li>
<li>静态代理设计模式的缺点:<ul>
<li><strong>当代理功能比较多时,代理类中方法需要写很多.</strong></li>
</ul>
</li>
</ul>
<h3 id="动态代理"><a href="#动态代理" class="headerlink" title="动态代理"></a>动态代理</h3><p><strong>为了解决静态代理频繁编写代理功能缺点.</strong></p>
<ul>
<li><p>分类:</p>
<ul>
<li><strong>JDK 提供的</strong></li>
<li><strong>cglib 动态代理</strong></li>
</ul>
</li>
<li><p><strong>JDK 动态代理</strong></p>
</li>
<li><p><strong>和 cglib 动态代理对比</strong></p>
<ul>
<li><strong>优点:jdk 自带,不需要额外导入 jar</strong></li>
</ul>
</li>
<li><p>缺点:</p>
<ul>
<li><strong>真实对象必须实现接口</strong></li>
<li><strong>利用反射机制.效率不高.</strong></li>
</ul>
</li>
</ul>
<p>使用 JDK 动态代理时可能出现下面异常<br><img src= "https://gitee.com/kylincw/images/raw/master/loading.gif" data-lazy-src="https://qiniu.codekylin.cn/img/20200405111541.png" alt=""></p>
<p><strong>出现原因:希望把接口对象转换为具体真实对象</strong></p>
<h3 id="cglib-动态代理"><a href="#cglib-动态代理" class="headerlink" title="cglib 动态代理"></a>cglib 动态代理</h3><ul>
<li>cglib 优点:<ul>
<li><strong>基于字节码,生成真实对象的子类.</strong></li>
<li><strong>运行效率高于 JDK 动态代理.</strong></li>
<li><strong>不需要实现接口</strong></li>
</ul>
</li>
<li>cglib 缺点:<br>  <strong>非 JDK 功能,需要额外导入 jar</strong></li>
<li>使用 springaop 时,只要出现 Proxy 和真实对象转换异常<ul>
<li>设置为 true 使用 cglib</li>
<li>设置为 false 使用 jdk(默认值) <figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">&lt;aop:aspectj-autoproxy proxy-target-class=&quot;true&quot;&gt;&lt;/aop:aspectj-autoproxy&gt;</span><br></pre></td></tr></table></figure>




</li>
</ul>
</li>
</ul>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="mailto:undefined">Kylin</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="https://www.codekylin.cn/27466.html">https://www.codekylin.cn/27466.html</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://www.codekylin.cn" target="_blank">Kylin</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/spring/">spring</a><a class="post-meta__tags" href="/tags/aop/">aop</a><a class="post-meta__tags" href="/tags/%E9%9D%A2%E5%90%91%E5%88%87%E9%9D%A2%E7%BC%96%E7%A8%8B/">面向切面编程</a><a class="post-meta__tags" href="/tags/Schema-based/">Schema-based</a><a class="post-meta__tags" href="/tags/%E5%89%8D%E7%BD%AE%E9%80%9A%E7%9F%A5/">前置通知</a><a class="post-meta__tags" href="/tags/%E5%90%8E%E7%BD%AE%E9%80%9A%E7%9F%A5/">后置通知</a><a class="post-meta__tags" href="/tags/%E5%BC%82%E5%B8%B8%E9%80%9A%E7%9F%A5/">异常通知</a><a class="post-meta__tags" href="/tags/%E7%8E%AF%E7%BB%95%E9%80%9A%E7%9F%A5/">环绕通知</a><a class="post-meta__tags" href="/tags/jdk%E5%8A%A8%E6%80%81%E4%BB%A3%E7%90%86/">jdk动态代理</a><a class="post-meta__tags" href="/tags/cglib%E5%8A%A8%E6%80%81%E4%BB%A3%E7%90%86/">cglib动态代理</a></div><div class="post_share"><div class="social-share" data-image="https://qiniu.codekylin.cn/github/img/img/wallhaven-nm97v9.jpg" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/social-share.js/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/social-share.js/dist/js/social-share.min.js" defer></script></div></div><div class="post-reward"><div class="reward-button button--animated"><i class="fas fa-qrcode"></i> 打赏</div><div class="reward-main"><ul class="reward-all"><li class="reward-item"><a href="https://qiniu.codekylin.cn/img/20200807181442.jpg" target="_blank"><img class="post-qr-code-img" data-lazy-src="https://qiniu.codekylin.cn/img/20200807181442.jpg" alt="微信"/></a><div class="post-qr-code-desc">微信</div></li><li class="reward-item"><a href="https://qiniu.codekylin.cn/img/20200807181505.jpg" target="_blank"><img class="post-qr-code-img" data-lazy-src="https://qiniu.codekylin.cn/img/20200807181505.jpg" alt="支付寶"/></a><div class="post-qr-code-desc">支付寶</div></li></ul></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/27146.html"><img class="prev-cover" data-lazy-src="https://qiniu.codekylin.cn/github/images/20200423185712.png" onerror="onerror=null;src='/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">Spring学习-6</div></div></a></div><div class="next-post pull-right"><a href="/43915.html"><img class="next-cover" data-lazy-src="https://qiniu.codekylin.cn/github/img/img/博客封面16.png" onerror="onerror=null;src='/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">Spring学习-4</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span> 相关推荐</span></div><div class="relatedPosts-list"><div><a href="/43083.html" title="Spring学习-1"><img class="cover" data-lazy-src="https://qiniu.codekylin.cn/github/img/img/wallhaven-49m1ek.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2019-10-30</div><div class="title">Spring学习-1</div></div></a></div><div><a href="/43275.html" title="Spring学习-2"><img class="cover" data-lazy-src="https://qiniu.codekylin.cn/github/images/20200718200005.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2019-10-31</div><div class="title">Spring学习-2</div></div></a></div><div><a href="/27082.html" title="Spring学习-3"><img class="cover" data-lazy-src="https://qiniu.codekylin.cn/github/img/img/wallhaven-4x28xo.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2019-10-31</div><div class="title">Spring学习-3</div></div></a></div><div><a href="/43915.html" title="Spring学习-4"><img class="cover" data-lazy-src="https://qiniu.codekylin.cn/github/img/img/博客封面16.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2019-11-02</div><div class="title">Spring学习-4</div></div></a></div><div><a href="/27146.html" title="Spring学习-6"><img class="cover" data-lazy-src="https://qiniu.codekylin.cn/github/images/20200423185712.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2019-11-03</div><div class="title">Spring学习-6</div></div></a></div><div><a href="/43723.html" title="Spring学习-7"><img class="cover" data-lazy-src="https://qiniu.codekylin.cn/github/img/img/wallhaven-yjy95k.png" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2019-12-11</div><div class="title">Spring学习-7</div></div></a></div></div></div><hr/><div id="post-comment"><div class="comment-head"><div class="comment-headline"><i class="fas fa-comments fa-fw"></i><span> 评论</span></div></div><div class="comment-wrap"><div><div class="vcomment" id="vcomment"></div></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="card-info-avatar is-center"><img class="avatar-img" data-lazy-src="https://qiniu.codekylin.cn/img/20200807181526.jpg" onerror="this.onerror=null;this.src='https://qiniu.codekylin.cn/github/img/friend_404.gif'" alt="avatar"/><div class="author-info__name">Kylin</div><div class="author-info__description">学习不易，努力努力~</div></div><div class="card-info-data"><div class="card-info-data-item is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">362</div></a></div><div class="card-info-data-item is-center"><a href="/tags/"><div class="headline">标签</div><div class="length-num">427</div></a></div><div class="card-info-data-item is-center"><a href="/categories/"><div class="headline">分类</div><div class="length-num">101</div></a></div></div><a class="button--animated" id="card-info-btn"><i class="fas fa-bookmark"></i><span>加入书签</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://github.com/kylincw" target="_blank" title="Github"><i class="iconfont icon-github"></i></a><a class="social-icon" href="tencent://message/?Menu=yes&amp;uin=171346168&amp;Service=300&amp;sigT=45a1e5847943b64c6ff3990f8a9e644d2b31356cb0b4ac6b24663a3c8dd0f8aa12a595b1714f9d45" target="_blank" title="qq"><i class="iconfont icon-qq"></i></a><a class="social-icon" href="https://space.bilibili.com/53836035" target="_blank" title="BiliBili"><i class="iconfont icon-bilibili-line"></i></a><a class="social-icon" href="mailto:zhang171346168@qq.com" target="_blank" title="Email"><i class="iconfont icon-email1"></i></a><a class="social-icon" href="/atom.xml" target="_blank" title="RSS"><i class="iconfont icon-rss"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn card-announcement-animation"></i><span>公告</span></div><div class="announcement_content">学习不易，努力努力！</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#AOP%EF%BC%88%E9%9D%A2%E5%90%91%E5%88%87%E9%9D%A2%E7%BC%96%E7%A8%8B%EF%BC%89"><span class="toc-number">1.</span> <span class="toc-text">AOP（面向切面编程）</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Schema-based-%E5%AE%9E%E7%8E%B0AOP"><span class="toc-number">2.</span> <span class="toc-text">Schema-based 实现AOP</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%89%8D%E7%BD%AE%E9%80%9A%E7%9F%A5"><span class="toc-number">2.1.</span> <span class="toc-text">前置通知</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%90%8E%E7%BD%AE%E9%80%9A%E7%9F%A5"><span class="toc-number">2.2.</span> <span class="toc-text">后置通知</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%BC%82%E5%B8%B8%E9%80%9A%E7%9F%A5"><span class="toc-number">2.3.</span> <span class="toc-text">异常通知</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%8E%AF%E7%BB%95%E9%80%9A%E7%9F%A5"><span class="toc-number">2.4.</span> <span class="toc-text">环绕通知</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%80%BB%E7%BB%93"><span class="toc-number">2.5.</span> <span class="toc-text">总结</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#AspectJ%E6%96%B9%E5%BC%8F%E5%AE%9E%E7%8E%B0AOP"><span class="toc-number">3.</span> <span class="toc-text">AspectJ方式实现AOP</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#xml"><span class="toc-number">3.1.</span> <span class="toc-text">xml</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%80%BB%E7%BB%93-1"><span class="toc-number">3.2.</span> <span class="toc-text">总结</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%B3%A8%E8%A7%A3"><span class="toc-number">3.3.</span> <span class="toc-text">注解</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BB%A3%E7%90%86%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F"><span class="toc-number">4.</span> <span class="toc-text">代理设计模式</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E9%9D%99%E6%80%81%E4%BB%A3%E7%90%86%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F"><span class="toc-number">4.1.</span> <span class="toc-text">静态代理设计模式</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%8A%A8%E6%80%81%E4%BB%A3%E7%90%86"><span class="toc-number">4.2.</span> <span class="toc-text">动态代理</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#cglib-%E5%8A%A8%E6%80%81%E4%BB%A3%E7%90%86"><span class="toc-number">4.3.</span> <span class="toc-text">cglib 动态代理</span></a></li></ol></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/56352.html" title="be动词"><img data-lazy-src="https://qiniu.codekylin.cn/github/img/img/博客封面10.png" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="be动词"/></a><div class="content"><a class="title" href="/56352.html" title="be动词">be动词</a><time datetime="2022-07-12T11:47:29.800Z" title="更新于 2022-07-12 19:47:29">2022-07-12</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/36436.html" title="JVM堆内存"><img data-lazy-src="https://qiniu.codekylin.cn/img/20200418115059.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="JVM堆内存"/></a><div class="content"><a class="title" href="/36436.html" title="JVM堆内存">JVM堆内存</a><time datetime="2022-07-12T11:47:29.800Z" title="更新于 2022-07-12 19:47:29">2022-07-12</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/44292.html" title="Java多线程详解"><img data-lazy-src="https://qiniu.codekylin.cn/github/img/img/wallhaven-eorjzk.png" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Java多线程详解"/></a><div class="content"><a class="title" href="/44292.html" title="Java多线程详解">Java多线程详解</a><time datetime="2022-07-12T11:47:29.800Z" title="更新于 2022-07-12 19:47:29">2022-07-12</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/40200.html" title="谷粒商城记录"><img data-lazy-src="https://qiniu.codekylin.cn/github/img/img/wallhaven-6qvvrx.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="谷粒商城记录"/></a><div class="content"><a class="title" href="/40200.html" title="谷粒商城记录">谷粒商城记录</a><time datetime="2022-07-12T11:47:29.800Z" title="更新于 2022-07-12 19:47:29">2022-07-12</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/27082.html" title="Spring学习-3"><img data-lazy-src="https://qiniu.codekylin.cn/github/img/img/wallhaven-4x28xo.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Spring学习-3"/></a><div class="content"><a class="title" href="/27082.html" title="Spring学习-3">Spring学习-3</a><time datetime="2022-07-12T11:47:29.799Z" title="更新于 2022-07-12 19:47:29">2022-07-12</time></div></div></div></div></div></div></main><footer id="footer" style="background-image: url('https://qiniu.codekylin.cn/github/img/img/wallhaven-nm97v9.jpg')"><div id="footer-wrap"><div class="copyright">&copy;2019 - 2022 By Kylin</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div><div class="footer_custom_text"><a target="_blank" rel="noopener" href="https://beian.miit.gov.cn/"><img class="icp-icon" src="https://img.alicdn.com/tfs/TB1..50QpXXXXX7XpXXXXXXXXXX-40-40.png"><span>湘ICP备2022005420号-1</span></a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="font-plus" type="button" title="放大字体"><i class="fas fa-plus"></i></button><button id="font-minus" type="button" title="缩小字体"><i class="fas fa-minus"></i></button><button id="translateLink" type="button" title="简繁转换">繁</button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><a id="to_comment" href="#post-comment" title="直达评论"><i class="fas fa-comments"></i></a><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div id="local-search"><div class="search-dialog"><div class="search-dialog__title" id="local-search-title">本地搜索</div><div id="local-input-panel"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div></div><hr/><div id="local-search-results"></div><span class="search-close-button"><i class="fas fa-times"></i></span></div><div id="search-mask"></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="/js/tw_cn.js"></script><script src="https://cdn.jsdelivr.net/npm/instant.page/instantpage.min.js" type="module"></script><script src="https://cdn.jsdelivr.net/npm/vanilla-lazyload/dist/lazyload.iife.min.js"></script><script src="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.js"></script><script src="/js/search/local-search.js"></script><div class="js-pjax"><script>function loadValine () {
  function initValine () {
    const valine = new Valine(Object.assign({
      el: '#vcomment',
      appId: 'ClIyIUhj1ue2rcRTsApYCR50-gzGzoHsz',
      appKey: 'ATug9IScYQBHILhKWEqBHYxM',
      placeholder: '昵称填入QQ号能获取到QQ头像哦~请输入正确的邮箱地址，你将会快速收到我的回复并且通过邮件通知你！~',
      avatar: 'robohash',
      meta: 'nick,mail,link'.split(','),
      pageSize: '10',
      lang: 'zh-cn',
      recordIP: false,
      serverURLs: 'https://cliyiuhj.lc-cn-n1-shared.com',
      emojiCDN: '',
      emojiMaps: "",
      enableQQ: true,
      path: window.location.pathname,
      requiredFields: ["nick,mail"],
      visitor: false
    }, null))
  }

  if (typeof Valine === 'function') initValine() 
  else getScript('https://cdn.jsdelivr.net/npm/valine/dist/Valine.min.js').then(initValine)
}

if ('Valine' === 'Valine' || !true) {
  if (true) btf.loadComment(document.getElementById('vcomment'),loadValine)
  else setTimeout(loadValine, 0)
} else {
  function loadOtherComment () {
    loadValine()
  }
}</script></div><script defer="defer" id="ribbon" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/canvas-ribbon.min.js" size="150" alpha="0.6" zIndex="-1" mobile="false" data-click="true"></script><script defer="defer" id="fluttering_ribbon" mobile="false" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/canvas-fluttering-ribbon.min.js"></script></div></body></html>